package com.lzm.back.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzm.back.entity.EventCategory;
import com.lzm.back.mapper.EventCategoryMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EventCategoryService {

    @Resource
    private EventCategoryMapper categoryMapper;


    public void postEventCategory(EventCategory eventCategory) {
        categoryMapper.insert(eventCategory);
        System.out.println(eventCategory);

    }

    public void delEventCategory(Long id) {
        // 删除
        categoryMapper.deleteByPrimaryKey(id);
    }

    public void delEventCategoryBaTch(List<Long> ids) {
        for (Long id : ids) {
            categoryMapper.deleteByPrimaryKey(id);
        }
    }


    public void putEventCategory(EventCategory eventCategory) {
        categoryMapper.updateByPrimaryKey(eventCategory);
        System.out.println(eventCategory);
    }


    public PageInfo<EventCategory> selectPage(EventCategory eventCategory,
                                              String name,
                                              Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);

        List<EventCategory> eventCategoryList = categoryMapper.selectByCondition(name);
        return PageInfo.of(eventCategoryList);
    }


    public List<EventCategory> listAll() {

        return categoryMapper.selectByCondition(null);
    }
}

